﻿using System.Collections.Generic;
using Prodma.DataAccess.Interfaces.Models;
using System.Linq;

namespace Prodma.DataAccess.Models.ViewModels
{
    public class PagedObject<T> : List<T>
    {
        public int Index { get; set; }
        public int Size { get; set; }
        public int Count { get; set; }
        public int TotalPage { get; set; }

        public PagedObject(IQueryable<T> source, int currentPage, int pageSize)
        {
            Index = currentPage;
            Size = pageSize;
            Count = source.Count();
            TotalPage = Count / Size;

            this.AddRange(source.Skip(Index * Size).Take(Size));
        }

        public bool HasPrePage
        {
            get { return (Size > 0); }
        }

        public bool HasNextPage
        {
            get { return (Index + 1 < TotalPage); }
        }
    }
}
